<template>
	<section>
		<!--高级查询-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.keyword" placeholder="关键字"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="search">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="productOrders" highlight-current-row v-loading="listLoading"
				  @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="selection" width="55">
			</el-table-column>
			<el-table-column prop="orderSn" label="编号" width="120" sortable>
			</el-table-column>
			<el-table-column prop="digest" label="摘要" width="180" sortable>
			</el-table-column>
			<el-table-column prop="state" label="状态" width="100" sortable>
				<template scope="scope">
					<span style="color: deeppink;" v-if="scope.row.state === 0">待支付</span>
					<span style="color: aquamarine" v-else-if="scope.row.state === 1">待发货</span>
					<span style="color: coral" v-else-if="scope.row.state === 2">待确认</span>
					<span style="color: green;" v-else-if="scope.row.state === 3">已完成</span>
					<span style="color: gray;" v-else-if="scope.row.state === -1">取消</span>
					<span style="color: dimgray;"v-else>未知</span>
				</template>
			</el-table-column>
			<el-table-column prop="price" label="价格" width="120" sortable>
			</el-table-column>
			<el-table-column prop="lastPayTime" label="最后支付时间" width="120" sortable>
			</el-table-column>
			<el-table-column prop="lastConfirmTime" label="最后确认时间" width="120" sortable>
			</el-table-column>
			<el-table-column label="操作" >
				<template scope="scope">
					<el-button size="small" @click="orderInfo(scope.$index, scope.row)">详情</el-button>
					<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--分页条-->
		<el-col :span="24" class="toolbar">
			<el-button type="danger" :disabled="this.sels.length===0">批量删除</el-button>
			<el-pagination layout="prev, pager, next"
						   @current-change="handleCurrentChange"
						   :page-size="pageSize"
						   :total="total"
						   :current-page="currentPage"
						   style="float:right;">
			</el-pagination>
		</el-col>



	</section>
</template>

<script>
    export default {
        data() {
            return {
                title:"",
                filters: {
                    keyword: ''
                },
                productOrders: [],
                total: 0,
                currentPage: 1,
                pageSize:10,
                listLoading: false,
                sels: [],//列表选中行
                productOrderInfoVisible:false,
                productOrderInfo:{
                    pet:{},
                    shop:{},
                    user:{}
                }
            }
        },
        methods: {
            orderInfo(index,row){
                //this.productOrderInfo = Object.assign({}, row);//克隆一份数据用来做回显
                let orderId = row.id;
                this.$http.get("/productOrder/"+orderId)
                    .then(result=>{
                        this.productOrderInfoVisible = true;//显示编辑窗口
                        this.productOrderInfo = result.data;//ProductOrder
                    })
                    .catch(result=>{

                    })
            },
            search(){//做高级查询,一定要定位到第一页
                this.currentPage = 1;
                this.getProductOrders();
            },
            handleCurrentChange(val) {
                this.currentPage = val;//点击页码之后给模型层赋值
                this.getProductOrders();
            },
            //获取领养订单列表
            getProductOrders() {
                let para = {
                    currentPage: this.currentPage,
                    pageSize: this.pageSize,
                    keyword: this.filters.keyword
                };

                this.listLoading = true;//开启忙等框
                //NProgress.start();
                //发送axios请求从后端  8080 拿数据
                this.$http.post("/productOrder/admin",para)
                    .then(result=>{
                        this.listLoading = false;//开启忙等框
                        console.log(result);//
                        result = result.data;//PageList
                        this.productOrders = result.rows;
                        this.total = result.total;
                    })
                    .catch(result=>{
                        console.log(result);
                        this.$message({
                            type: 'error',
                            message: '系统错误,我们正在和程序员小哥哥勾兑!!'
                        });
                    });
            },
            selsChange: function (sels) {//复选框勾选的时候触发 当前复选框选中的所有行的数据
                this.sels = sels;
            }
        },
        mounted() {
            this.getProductOrders();
        }
    }

</script>

<style scoped>

</style>
